﻿using Entity.BaseInfo.DTO.Goods;
using Entity.BaseInfo.View.Goods;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.BaseInfo;

namespace AnQinManagermentBackendAPI.Controller.BaseInfo
{
    /// <summary>
    /// 物料表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class GoodsController : ControllerBase
    {
        /**
         * 物料业务接口
         */
        private readonly GoodsService _goodsService;

        /**
         * 构造函数注入
         */
        public GoodsController(GoodsService goodsService)
        {
            _goodsService = goodsService;
        }

        /// <summary>
        /// 获取物料列表
        /// </summary>
        /// <param name="goodsSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(GoodsView), 200)]
        public async Task<IActionResult> GetGoodsList([FromQuery] GoodsSearchDTO goodsSearchDTO)
        {
            var response = await _goodsService.GetGoodsList(goodsSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增物料
        /// </summary>
        /// <param name="goodsAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddGoods([FromBody] GoodsAddDTO goodsAddDTO)
        {
            var response = await _goodsService.AddGoods(goodsAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新物料
        /// </summary>
        /// <param name="goodsUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutGoods([FromBody] GoodsUpdateDTO goodsUpdateDTO)
        {
            var response = await _goodsService.PutGoods(goodsUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除物料
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteGoods([FromQuery] string Id)
        {
            var response = await _goodsService.DeleteGoods(Id);
            return StatusCode(response.Status, response);
        }
    }
}
